/**
	Pulsar engine. Core.
	File drives - windows extension

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

namespace pl
{

class DriveWin : public Drive
{
public:
	virtual bool isAccepted(const pl::Filepath& fileName) const;

	virtual pl::FileError getTotalDiskSpace(const pl::Filepath& fileName, pl_uint64 &nBytes) const;

	virtual pl::FileError getFreeDiskSpace(const pl::Filepath& fileName, pl_uint64 &nBytes) const;

	virtual pl::FileError renameFile(const pl::Filepath& oldName, const pl::Filepath& newName);

	virtual pl::FileError deleteFile(const pl::Filepath& fileName);

	virtual pl::FileError makeDir(const pl::Filepath& dirName);

	virtual pl::FileError deleteDir(const pl::Filepath& dirName);

	virtual pl::FileError checkFileExist(const pl::Filepath& fileName);

	virtual pl::FileError getFileAttrib(const pl::Filepath& fileName, pl_uint32& attrib);

	virtual pl::FileError setFileAttrib(const pl::Filepath& fileName, pl_uint32 attrib);

	virtual pl::FileError getFileSize(const pl::Filepath& fileName, pl_int64& size);

	virtual pl::FileError setFileSize(const pl::Filepath& fileName, pl_int64 size);

	virtual pl::FileError getFileDate(const pl::Filepath& fileName, pl::FileDateType type, pl::DateTime& date);

	virtual pl::FileError setFileDate(const pl::Filepath& fileName, pl::FileDateType type, const pl::DateTime& date);

	virtual pl::FindFile* findFile(const pl::Filepath& mask);

	virtual pl::StreamRead* openFileRead(const pl::Filepath& fileName, pl_uint32 options);

	virtual pl::StreamWrite* openFileWrite(const pl::Filepath& fileName, pl_uint32 options);
};

class FindFileWin : public FindFile
{
public:
	explicit FindFileWin(const pl::Filepath& mask);
	~FindFileWin();

	virtual bool isFinished();

	inline bool isFound() const
	{
		return _bFileFound && _hFind != INVALID_HANDLE_VALUE;
	}

	virtual const pl::Filepath& getFileName() const
	{
		PL_ASSERTW(isFound(), PL_T("No more files in FindFile interface"));
		return _fileName;
	}

	virtual pl_int64 getFileSize() const
	{
		PL_ASSERTW(isFound(), PL_T("No more files in FindFile interface"));
		return _size;
	}

	virtual pl_uint32 getFileAttrib() const
	{
		PL_ASSERTW(isFound(), PL_T("No more files in FindFile interface"));
		return _attrib;
	}

	virtual const pl::DateTime& getFileDate(FileDateType type) const;

private:
	HANDLE _hFind;
	pl::Filepath _fileName;
	pl_uint64 _size;
	pl_uint32 _attrib;
	pl::DateTime _dateCreate;
	pl::DateTime _dateModify;
	pl::DateTime _dateAccess;
	bool _bFileFound;
	bool _bFirstCall;
};

} // namespace pl

//
// End of file 'pulsar_filedrive_impl_win.h'
//
